<%@page import="org.proddevplm.dao.data.administration.Statistics"%>
<%@page import="org.proddevplm.dao.data.Roles"%>
<%@page import="java.util.List"%>
<%@page import="org.proddevplm.constants.ControllerConstants"%>
<%@page import="org.proddevplm.business.administration.constants.AdminConstants"%>

<script type="text/javascript">

	$(document).ready(function() {
		$("#showInstructionsDiv").hide();
	});
	
	$(function(){
		$( "button" ).button();
		$("#setAccessTable").tablesorter({
			widgets:['zebra'],
			headers:{
				1:{sorter: false}
			}
		})
		
	});
	
	function showInstructions(){
		$("#showInstructionsDiv").show();
	}
	
	function hideInstructions(){
		$("#showInstructionsDiv").hide();
	}
	
	function selectedLevel(accessLevel, roleId){
		var arguments = "accessLevel="+accessLevel+"&roleId="+roleId;
		ajaxCall("adminManager", "0", arguments, null);
	}
	
	function doneLevels(){
		document.forms["LevelsFWD"].submit();
	}

</script>
	
<%
	List allRoles = (List)session.getAttribute("allRoles");
	Statistics statResAccessLevels = (Statistics)session.getAttribute("statResAccessLevels");
%>

<%if((statResAccessLevels!=null) && (statResAccessLevels.getStatus())) {%>
	<div style="width:100%;">
		<p>The access levels were already configured. Please choose the <b><i>Edit access levels</i></b> tab to make changes</p>
	</div>
	<%}else{ %>
		<div style="width:100%;">	
			
			<div style="width:50%; float:left;">
				<table class="tablesorter" id="setAccessTable" border="1" cellspacing="0" cellpadding="3" rules="rows" frame="hsides" bordercolor="#DBDBDB" style="width:100%; font-family:verdana">
					<thead>
						<tr>
							<th style="width:75%; text-align:left">Role</th>
							<th style="text-align:center">Access level</th>
						</tr>
					</thead>
					<tbody>
						<%for(int i=0; i<allRoles.size(); i++){
							Roles r = (Roles)allRoles.get(i);
						%>
						<tr>
							<td><%=r.getRole() %></td>
							<td style="text-align:center">
								<select name="accessLevel" onChange="selectedLevel(this.options[selectedIndex].value, '<%=r.getId()%>')" size="1" style="width:50px">
									<%for(int j=0; j<5; j++){ %>
										<option value="<%=j %>"><%=j %></option>
									<%} %>
								</select>
							</td>
						</tr>
						<%} %>
					</tbody>
				</table>
				
				<div style="margin-top:10px; float:right">
					<button id="doneLevels" name="doneLevels" onclick="doneLevels()" style="width:200px; font-weight:bold">Done</button>
				</div>
				
			</div>
			
			<div id="seeHelp" style="float:left; width:48%; padding:10px">
				<button name="showInstructions" id="showInstructions" onclick="showInstructions()" style="width:40%; font-weight:bold; float:left;">Show instructions</button>
				<button name="hideInstructions" id="hideInstructions" onclick="hideInstructions()" style="width:40%; font-weight:bold; float:right;">Hide instructions</button>
				<div style="clear:both"></div>
				<div id="showInstructionsDiv" style="margin-top:10px; background-color:#F0F0F6; padding: 0.5%; -moz-border-radius: 5px; -moz-box-shadow: 10px 10px 5px #888888; border: 1px solid #DBDBDB; color:#555555">
					<p style="font-weight:bold;">Please set the access level based on the following recommendations</p>
					<p>0 - administrator</p>
					<p>1 - project manager</p>
					<p>2 - manager</p>
					<p>3 - member - intern</p>
					<p>4 - member - extern</p>
				</div>
			
			</div>
			
			<form name="LevelsFWD" id="LevelsFWD" action="/proddev/controller">
				<input type = "hidden" name = "<%=ControllerConstants.MANAGER_KEY%>" value = "<%=ControllerConstants.ADMIN_MANAGER %>"/>
				<input type = "hidden" name = "<%=ControllerConstants.METHOD_KEY%>" value = "<%=AdminConstants.ADMIN_FWD%>"/>			
			</form>
			
			<div style="clear:both"></div>
		</div>
	<%}%>